﻿CREATE FUNCTION fnObtenEstudiosPaquete(@pnIdPaquete INT, @pnIdLaboratorio INT)
RETURNS NVARCHAR(MAX)
AS
BEGIN
	DECLARE @sEstudios NVARCHAR(MAX)
	
	SELECT	@sEstudios		= COALESCE(@sEstudios + CHAR(13) + CHAR(10) + CHAR(9),'') + e.NombreEstudio
	FROM	dbo.PaqueteEstudioDet	pe
	INNER JOIN dbo.CatEstudio		e
	ON		pe.IdLaboratorio= e.IdLaboratorio 
	AND		pe.IdEstudio	= e.IdEstudio
	AND		e.BajaLogica	= 0
	WHERE	pe.IdPaquete		= @pnIdPaquete
	AND		pe.IdLaboratorio	= @pnIdLaboratorio
	
	RETURN @sEstudios
END